<!DOCTYPE HTML>
<html lang="zh-tw" >
    <!-- Start book python基础语言 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>深拷贝、浅拷贝 | python基础语言</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-emphasize/plugin.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../03day/section.6.html" />
    
    
    <link rel="prev" href="../03day/section.2.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="2.5"
        data-chapter-title="深拷贝、浅拷贝"
        data-filepath="03day/section.1.md"
        data-basepath=".."
        data-revision="Fri Mar 17 2017 08:48:09 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        课程介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="01day/index.html">
            
                
                    <a href="../01day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        面向对象进阶
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="01day/section.1.0.html">
            
                
                    <a href="../01day/section.1.0.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        元类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="01day/section.1.1.html">
            
                
                    <a href="../01day/section.1.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        python是动态语言
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="01day/section.1.3.html">
            
                
                    <a href="../01day/section.1.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        __slots__
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="02day/section.4.html">
            
                
                    <a href="../02day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        生成器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="02day/section.3.html">
            
                
                    <a href="../02day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        迭代器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="02day/section.1.html">
            
                
                    <a href="../02day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        闭包
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="02day/section.2.html">
            
                
                    <a href="../02day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        装饰器
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="02day/index.html">
            
                
                    <a href="../02day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        其他的知识点
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="03day/section.0.2.html">
            
                
                    <a href="../03day/section.0.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        import导入模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="03day/section.1.1.html">
            
                
                    <a href="../03day/section.1.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        循环导入
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="03day/section.0.3.html">
            
                
                    <a href="../03day/section.0.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        作用域
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="03day/section.2.html">
            
                
                    <a href="../03day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        ==、is
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="2.5" data-path="03day/section.1.html">
            
                
                    <a href="../03day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        深拷贝、浅拷贝
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="03day/section.6.html">
            
                
                    <a href="../03day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        进制、位运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="01day/section.3.html">
            
                
                    <a href="../01day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        私有化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="01day/section.3.1.html">
            
                
                    <a href="../01day/section.3.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        属性property
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="03day/index.html">
            
                
                    <a href="../03day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        其他的知识点
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="03day/section.0.1.html">
            
                
                    <a href="../03day/section.0.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        垃圾回收(一)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="03day/section.0.1.1.html">
            
                
                    <a href="../03day/section.0.1.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        垃圾回收(二)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="03day/section.0.1.2.html">
            
                
                    <a href="../03day/section.0.1.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        垃圾回收(三)-gc模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="01day/section.4.html">
            
                
                    <a href="../01day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        内建属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="01day/section.6.html">
            
                
                    <a href="../01day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        内建函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="01day/section.7.html">
            
                
                    <a href="../01day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        集合set
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="02day/section.5.html">
            
                
                    <a href="../02day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        functools
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="03day/section.4.html">
            
                
                    <a href="../03day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="03day/section.3.html">
            
                
                    <a href="../03day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        调试
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="03day/section.5.html">
            
                
                    <a href="../03day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        编码风格
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本書使用 GitBook 釋出
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >python基础语言</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x6DF1;&#x62F7;&#x8D1D;&#x3001;&#x6D45;&#x62F7;&#x8D1D;">&#x6DF1;&#x62F7;&#x8D1D;&#x3001;&#x6D45;&#x62F7;&#x8D1D;</h1>
<h3 id="1-&#x6D45;&#x62F7;&#x8D1D;">1. &#x6D45;&#x62F7;&#x8D1D;</h3>
<ul>
<li>&#x6D45;&#x62F7;&#x8D1D;&#x662F;&#x5BF9;&#x4E8E;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x9876;&#x5C42;&#x62F7;&#x8D1D;</li>
</ul>
<p>&#x901A;&#x4FD7;&#x7684;&#x7406;&#x89E3;&#x662F;&#xFF1A;&#x62F7;&#x8D1D;&#x4E86;&#x5F15;&#x7528;&#xFF0C;&#x5E76;&#x6CA1;&#x6709;&#x62F7;&#x8D1D;&#x5185;&#x5BB9;</p>
<p><img src="../Images/Snip20161106_1.png" alt=""></p>
<p><img src="../Images/Snip20161106_2.png" alt=""></p>
<h2 id="2-&#x6DF1;&#x62F7;&#x8D1D;">2. &#x6DF1;&#x62F7;&#x8D1D;</h2>
<ul>
<li>&#x6DF1;&#x62F7;&#x8D1D;&#x662F;&#x5BF9;&#x4E8E;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x6240;&#x6709;&#x5C42;&#x6B21;&#x7684;&#x62F7;&#x8D1D;(&#x9012;&#x5F52;)</li>
</ul>
<p><img src="../Images/Snip20161106_3.png" alt=""></p>
<h5 id="&#x8FDB;&#x4E00;&#x6B65;&#x7406;&#x89E3;&#x62F7;&#x8D1D;">&#x8FDB;&#x4E00;&#x6B65;&#x7406;&#x89E3;&#x62F7;&#x8D1D;</h5>
<p><img src="../Images/Snip20161106_4.png" alt=""></p>
<pre><code class="lang-python">In [<span class="hljs-number">23</span>]: a = [<span class="hljs-number">11</span>,<span class="hljs-number">22</span>,<span class="hljs-number">33</span>]

In [<span class="hljs-number">24</span>]: b = [<span class="hljs-number">44</span>,<span class="hljs-number">55</span>,<span class="hljs-number">66</span>]

In [<span class="hljs-number">25</span>]: c = (a,b)

In [<span class="hljs-number">26</span>]: e = copy.deepcopy(c)

In [<span class="hljs-number">27</span>]: a.append(<span class="hljs-number">77</span>)

In [<span class="hljs-number">28</span>]: a
Out[<span class="hljs-number">28</span>]: [<span class="hljs-number">11</span>, <span class="hljs-number">22</span>, <span class="hljs-number">33</span>, <span class="hljs-number">77</span>]

In [<span class="hljs-number">29</span>]: b
Out[<span class="hljs-number">29</span>]: [<span class="hljs-number">44</span>, <span class="hljs-number">55</span>, <span class="hljs-number">66</span>]

In [<span class="hljs-number">30</span>]: c
Out[<span class="hljs-number">30</span>]: ([<span class="hljs-number">11</span>, <span class="hljs-number">22</span>, <span class="hljs-number">33</span>, <span class="hljs-number">77</span>], [<span class="hljs-number">44</span>, <span class="hljs-number">55</span>, <span class="hljs-number">66</span>])

In [<span class="hljs-number">31</span>]: e
Out[<span class="hljs-number">31</span>]: ([<span class="hljs-number">11</span>, <span class="hljs-number">22</span>, <span class="hljs-number">33</span>], [<span class="hljs-number">44</span>, <span class="hljs-number">55</span>, <span class="hljs-number">66</span>])

In [<span class="hljs-number">32</span>]: 

In [<span class="hljs-number">32</span>]: 

In [<span class="hljs-number">32</span>]: f = copy.copy(c)

In [<span class="hljs-number">33</span>]: a.append(<span class="hljs-number">88</span>)

In [<span class="hljs-number">34</span>]: a
Out[<span class="hljs-number">34</span>]: [<span class="hljs-number">11</span>, <span class="hljs-number">22</span>, <span class="hljs-number">33</span>, <span class="hljs-number">77</span>, <span class="hljs-number">88</span>]

In [<span class="hljs-number">35</span>]: b
Out[<span class="hljs-number">35</span>]: [<span class="hljs-number">44</span>, <span class="hljs-number">55</span>, <span class="hljs-number">66</span>]

In [<span class="hljs-number">36</span>]: c
Out[<span class="hljs-number">36</span>]: ([<span class="hljs-number">11</span>, <span class="hljs-number">22</span>, <span class="hljs-number">33</span>, <span class="hljs-number">77</span>, <span class="hljs-number">88</span>], [<span class="hljs-number">44</span>, <span class="hljs-number">55</span>, <span class="hljs-number">66</span>])

In [<span class="hljs-number">37</span>]: e
Out[<span class="hljs-number">37</span>]: ([<span class="hljs-number">11</span>, <span class="hljs-number">22</span>, <span class="hljs-number">33</span>], [<span class="hljs-number">44</span>, <span class="hljs-number">55</span>, <span class="hljs-number">66</span>])

In [<span class="hljs-number">38</span>]: f
Out[<span class="hljs-number">38</span>]: ([<span class="hljs-number">11</span>, <span class="hljs-number">22</span>, <span class="hljs-number">33</span>, <span class="hljs-number">77</span>, <span class="hljs-number">88</span>], [<span class="hljs-number">44</span>, <span class="hljs-number">55</span>, <span class="hljs-number">66</span>])
</code></pre>
<h2 id="3-&#x62F7;&#x8D1D;&#x7684;&#x5176;&#x4ED6;&#x65B9;&#x5F0F;">3. &#x62F7;&#x8D1D;&#x7684;&#x5176;&#x4ED6;&#x65B9;&#x5F0F;</h2>
<h5 id="&#x6D45;&#x62F7;&#x8D1D;&#x5BF9;&#x4E0D;&#x53EF;&#x53D8;&#x7C7B;&#x578B;&#x548C;&#x53EF;&#x53D8;&#x7C7B;&#x578B;&#x7684;copy&#x4E0D;&#x540C;">&#x6D45;&#x62F7;&#x8D1D;&#x5BF9;&#x4E0D;&#x53EF;&#x53D8;&#x7C7B;&#x578B;&#x548C;&#x53EF;&#x53D8;&#x7C7B;&#x578B;&#x7684;copy&#x4E0D;&#x540C;</h5>
<pre><code class="lang-python">In [<span class="hljs-number">88</span>]: a = [<span class="hljs-number">11</span>,<span class="hljs-number">22</span>,<span class="hljs-number">33</span>]

In [<span class="hljs-number">89</span>]: b = copy.copy(a)

In [<span class="hljs-number">90</span>]: id(a)
Out[<span class="hljs-number">90</span>]: <span class="hljs-number">59275144</span>

In [<span class="hljs-number">91</span>]: id(b)
Out[<span class="hljs-number">91</span>]: <span class="hljs-number">59525600</span>

In [<span class="hljs-number">92</span>]: a.append(<span class="hljs-number">44</span>)

In [<span class="hljs-number">93</span>]: a
Out[<span class="hljs-number">93</span>]: [<span class="hljs-number">11</span>, <span class="hljs-number">22</span>, <span class="hljs-number">33</span>, <span class="hljs-number">44</span>]

In [<span class="hljs-number">94</span>]: b
Out[<span class="hljs-number">94</span>]: [<span class="hljs-number">11</span>, <span class="hljs-number">22</span>, <span class="hljs-number">33</span>]

In [<span class="hljs-number">95</span>]:

In [<span class="hljs-number">95</span>]:

In [<span class="hljs-number">95</span>]: a = (<span class="hljs-number">11</span>,<span class="hljs-number">22</span>,<span class="hljs-number">33</span>)

In [<span class="hljs-number">96</span>]: b = copy.copy(a)

In [<span class="hljs-number">97</span>]: id(a)
Out[<span class="hljs-number">97</span>]: <span class="hljs-number">58890680</span>

In [<span class="hljs-number">98</span>]: id(b)
Out[<span class="hljs-number">98</span>]: <span class="hljs-number">58890680</span>
</code></pre>
<ul>
<li>&#x5206;&#x7247;&#x8868;&#x8FBE;&#x5F0F;&#x53EF;&#x4EE5;&#x8D4B;&#x503C;&#x4E00;&#x4E2A;&#x5E8F;&#x5217;</li>
</ul>
<pre><code class="lang-python">    a = <span class="hljs-string">&quot;abc&quot;</span>

    b = a[:]
</code></pre>
<ul>
<li>&#x5B57;&#x5178;&#x7684;copy&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x62F7;&#x8D1D;&#x4E00;&#x4E2A;&#x5B57;&#x5178;</li>
</ul>
<pre><code class="lang-python">    d = dict(name=<span class="hljs-string">&quot;zhangsan&quot;</span>, age=<span class="hljs-number">27</span>)

    co = d.copy()
</code></pre>
<ul>
<li>&#x6709;&#x4E9B;&#x5185;&#x7F6E;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x751F;&#x6210;&#x62F7;&#x8D1D;(list)</li>
</ul>
<pre><code class="lang-python">    a = list(range(<span class="hljs-number">10</span>))

    b = list(a)
</code></pre>
<ul>
<li>copy&#x6A21;&#x5757;&#x4E2D;&#x7684;copy&#x51FD;&#x6570;</li>
</ul>
<pre><code class="lang-python">    <span class="hljs-keyword">import</span> copy

    a = (<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>)

    b = copy.copy(a)
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../03day/section.2.html" class="navigation navigation-prev " aria-label="Previous page: ==、is"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../03day/section.6.html" class="navigation navigation-next " aria-label="Next page: 进制、位运算"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"toggle-chapters":{},"splitter":{},"emphasize":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book python基础语言 -->
</html>
